package com.itmyx.sys.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.itmyx.base.controller.BaseController;
import com.itmyx.base.util.data.ParamData;
import com.itmyx.base.util.data.Result;
import com.itmyx.sys.service.RoleService;
/**
 * 功能描述  控制器类
 * @类型名称 RoleController
 * @版本 1.0
 * @创建者 
 * @创建时间 
 * @版权所有 @2016 ITMYX
 * @修改者 
 * @修改时间 
 * @修改描述
 */
@Controller
public class RoleController extends BaseController{
	
    @Autowired
	private RoleService roleService;
	

    
	@RequestMapping(value="/getRoleList",method=RequestMethod.POST)
	public @ResponseBody String getRoleList(){
		Result result = null;
		ParamData param=this.getPageData();//获取请求数据
		logBefore(logger,"查询列表","getRoleList",param);
		try {
			result = new Result(1, roleService.getList(param), null, null);//执行业务逻辑
		} catch (Exception e) {
			result = new Result(0, null, "获取失败", null);
			e.printStackTrace();
		}
		logAfter(logger,result.toJson());
		return result.toJson();
	}
    
	@RequestMapping(value="/getRoleById",method=RequestMethod.POST)
	public @ResponseBody String getRoleById(){
		Result result = null;
		ParamData param=this.getPageData();//获取请求数据
		logBefore(logger,"根据主键获取","addRole",param);
		try {
			result = new Result(1,roleService.getById(param), null, null);//执行业务逻辑
		} catch (Exception e) {
			e.printStackTrace();
		}
		logAfter(logger,result.toJson());
		return result.toJson();
	}
	
	@RequestMapping(value="/addRole",method=RequestMethod.POST)
	public @ResponseBody String addRole(){
		Result result = null;
		ParamData param=this.getPageData();//获取请求数据
		logBefore(logger,"添加","addRole",param);
		try {
			result = new Result(1, roleService.add(param), null, null);//执行业务逻辑
		} catch (Exception e) {
			result = new Result(0, null, "添加失败", null);
			e.printStackTrace();
		}
		logAfter(logger,result.toJson());
		return result.toJson();
	}
    
	@RequestMapping(value="/updateRole",method=RequestMethod.POST)
	public @ResponseBody String updateRole(){
		Result result = null;
		ParamData param=this.getPageData();//获取请求数据
		logBefore(logger,"更新User","updateRole",param);
		try {
			if(roleService.updateById(param)){
				result = new Result(1,null, "更新成功", null);
			}else{
				result = new Result(0,null, "更新失败", null);
			}
			
		} catch (Exception e) {
			result = new Result(0, null, "添加失败服务器异常", null);
			e.printStackTrace();
		}
		logAfter(logger,result.toJson());
		return result.toJson();
	}
	
	@RequestMapping(value="/deleteRoleById",method=RequestMethod.POST)
	public @ResponseBody String deleteRoleById(){
		Result result = null;
		ParamData param=this.getPageData();//获取请求数据
		logBefore(logger,"删除","deleteRoleById",param);
		try {
			if(roleService.deleteById(param)){
				result = new Result(1,null, "删除成功", null);//执行业务逻辑
			}else{
				result = new Result(0,null, "删除失败", null);//执行业务逻辑
			}
			
		} catch (Exception e) {
			result = new Result(0, null, "删除失败服务器异常", null);
			e.printStackTrace();
		}
		logAfter(logger,result.toJson());
		return result.toJson();
	}
}
